﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Transactions;
using System.Web.Services;
using MemberServerBLL;
using System.Text.RegularExpressions;


public partial class ControlPanel_Member_UserReg : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Convert.ToBoolean(ConfigurationManager.AppSettings["AllowReg"]))
        {
            Response.Write("<br/>不允许用户注册，如果需要注册，请开启允许用户注册选项(Membership.config或者系统配置");
            Response.End();
        }
        if (!IsPostBack)
        {
            //新注册用户，赋予默认图片
            Session["ImageType"] = "image/pjpeg";
            Session["ImageData"] = Convert.FromBase64String("/9j/4AAQSkZJRgABAQEBLAEsAAD/2wBDAAYEBAQFBAYFBQYJBgUGCQsIBgYICwwKCgsKCgwQDAwMDAwMEAwODxAPDgwTExQUExMcGxsbHCAgICAgICAgICD/2wBDAQcHBw0MDRgQEBgaFREVGiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICD/wAARCAB4AKADAREAAhEBAxEB/8QAHAABAAIDAQEBAAAAAAAAAAAAAAQGAwUHAgEI/8QAPBAAAQMDAwIFAgQEBAUFAAAAAgEDBAAFEQYSIRMxBxQiQVEyYRUjQoEXUnGRFiVDoSQzNGJyc4Kx0fD/xAAaAQEAAwEBAQAAAAAAAAAAAAAAAQIDBAUG/8QANxEAAgECBAMFBQcFAQEAAAAAAAECAxEEEiExQVFhBRMUcZEiMoGh8AYVQrHB0eEjM1JicjSi/9oADAMBAAIRAxEAPwD9U0AoBQCgFAKAUAoBQCgFAKAUAoBQCgFAKAUAoCPcX349vlSI7fWfZaNxplVxvMRVRHPOMrxUxV2Vm7JtFCc8XWRbckJCRYo2f8RB3qd5nRB/yfbj8t0Vz/tXb4Lrrmt8OZ5/3hxtplv8d7G6DxK0wEUnZb5MGyCk6vRe6ZE04LL6MmoIjv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2t8N/CUDdz3/DRtJIv/qTC0IL5bIxR4wtL7UBLoBQCgGKA+bU+KA+4SgFAKAYSgFAKAYoD5sH4SgPuEoD5hPigPtAKAUAoBQH/2Q==");
            //标记用户不存在
            Session["UserExists"] = false;
        }
    }

    #region WebService

    /// <summary>
    /// 检验用户名
    /// </summary>
    /// <param name="contextKey"></param>
    /// <returns></returns>
    [System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public static string ValidateUser(string contextKey)
    {
        // A little pause to mimic a latent call
        System.Threading.Thread.Sleep(250);
        string result = @"<span style='font-family:courier new;font-weight:bold;color:Red'>请输入您要注册的用户名</span>";

        if (contextKey == null || contextKey == "")
        {
            HttpContext.Current.Session["UserExists"] = true;
            return result;
        }

        if (Membership.FindUsersByName(contextKey).Count != 0)
        {
            HttpContext.Current.Session["UserExists"] = true;
            result = String.Format("<span style='font-family:courier new;font-weight:bold;color:Red'>用户名：{0} 已经有人使用</span>", contextKey);
        }
        else
        {
            HttpContext.Current.Session["UserExists"] = false;
            result = String.Format("<span style='font-family:courier new;font-weight:bold;color:Red'>恭喜，用户名 {0} 可以注册!!</span>", contextKey);

        }
        return result;
    }

    /// <summary>
    /// 检验电子邮件
    /// </summary>
    /// <param name="contextKey"></param>
    /// <returns></returns>
    [System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public static string ValidateEmail(string contextKey)
    {
        // A little pause to mimic a latent call
        System.Threading.Thread.Sleep(250);
        string result = @"<span style='font-family:courier new;font-weight:bold;color:Red'>请输入您的电子邮件</span>";

        if (contextKey == null || contextKey == "")
        {
            HttpContext.Current.Session["UserExists"] = true;
            return result;
        }

        Regex mailRegex = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
        if (!mailRegex.IsMatch(contextKey))
        {
            HttpContext.Current.Session["UserExists"] = true;
            result = @"<span style='font-family:courier new;font-weight:bold;color:Red'>您输入的电子邮件格式错误</span>";
        }
        else
        {
            if (Membership.FindUsersByEmail(contextKey).Count != 0)
            {
                HttpContext.Current.Session["UserExists"] = true;
                result = String.Format("<span style='font-family:courier new;font-weight:bold;color:Red'>电子邮件：{0} 已经有人使用</span>", contextKey);
            }
            else
            {
                HttpContext.Current.Session["UserExists"] = false;
                result = String.Format("<span style='font-family:courier new;font-weight:bold;color:Red'>电子邮件 {0} 可以注册!!</span>", contextKey);

            }
        }


        return result;
    }

    [System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public static string GetHtml(string contextKey)
    {
        // A little pause to mimic a latent call
        System.Threading.Thread.Sleep(250);

        string value = (contextKey == "U") ?
            DateTime.UtcNow.ToString() :
            String.Format("{0:" + contextKey + "}", DateTime.Now);
        return String.Format("<span style='font-family:courier new;font-weight:bold;'>{0}</span>", value);
    }
    #endregion
}
